import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from "../views/Login.vue"
import Updata from "../views/Updata.vue"
Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    name:localStorage.getItem("token")?"home":"login",
    component:localStorage.getItem("token")?Home:Login,
  },
  {
    path: '/home',
    name:"home",
    component:Home
  },
  {
    path: '/updata',
    name:"updata",
    component:Updata
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// router.beforeEach((to, from, next) => {
//   if (to.name !== 'login' && !localStorage.getItem("token")) {
//       next({ name: 'login' })
//   }
//   next()
// })
export default router
